// pages/options/options.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    navindex: 0,
    scrollTop: 0,
    scrollHeight:'',
    hidden:true,
    chose_c:true,
    martop:'170',
    tabbarIndex:'',
    freightnav: [
      { txt: '全部' },
      { txt: '熟车' },
    ],
    choseB: [
      { baby: '4.2米' },
      { baby: '5.5米' },
      { baby: '5.5米' },
      { baby: '5.5米' },
      { baby: '5.5米' },
      { baby: '5.5米' },
      { baby: '全部' },
    ],
    choseC: [
      { buyx: '不限' },
      { buyx: '平板' },
      { buyx: '高栏' },
      { buyx: '全部' },
    ],
    freight: [
      {
        time: '40分钟', pic: '/images/icon.png', name: '刘师傅', legend: '50KM', numbers: '冀A1234', long: '6.8米/高栏', city: '西安', distance:'20'
      },
      {
        time: '40分钟', pic: '/images/icon.png', name: '刘师傅', legend: '50KM', numbers: '冀A1234', long: '6.8米/高栏', city: '西安', distance: '20'
      },
      {
        time: '40分钟', pic: '/images/icon.png', name: '刘师傅', legend: '50KM', numbers: '冀A1234', long: '6.8米/高栏', city: '西安', distance: '20'
      },  
      {
        time: '40分钟', pic: '/images/icon.png', name: '刘师傅', legend: '50KM', numbers: '冀A1234', long: '6.8米/高栏', city: '西安', distance: '20'
      }, 
      {
        time: '40分钟', pic: '/images/icon.png', name: '刘师傅', legend: '50KM', numbers: '冀A1234', long: '6.8米/高栏', city: '西安', distance: '20'
      },
      {
        time: '40分钟', pic: '/images/icon.png', name: '刘师傅', legend: '50KM', numbers: '冀A1234', long: '6.8米/高栏', city: '西安', distance: '20'
      },
      {
        time: '40分钟', pic: '/images/icon.png', name: '刘师傅', legend: '50KM', numbers: '冀A1234', long: '6.8米/高栏', city: '西安', distance: '20'
      },
      {
        time: '40分钟', pic: '/images/icon.png', name: '刘师傅', legend: '50KM', numbers: '冀A1234', long: '6.8米/高栏', city: '西安', distance: '20'
      },  
    ],
  },
  //司机详情
  optionsdeil(e){
    var id = e.currentTarget.dataset.id;
    app.navTo('../optionsdeil/optionsdeil?id' +id)
  },
  changecity: function (cityName, type) {
    if (type == 0) {
      console.log("出发城市" + cityName)
      this.setData({
        city: cityName
      })
    }
    else if (type == 1) {
      console.log("送货城市" + cityName)
      this.setData({
        city1: cityName
      })
    }
  },
  //加入熟车
  chosecar:function(e){
    var index = e.currentTarget.dataset.index;
    var freight = this.data.freight;
    freight.splice(index,1);
    wx.showToast({
      title: '加入熟车',
      icon: 'success',
      duration: 2000,
    })
    this.setData({
      freight: freight
    })
  },
  //地址
  start_ads: function (e) {
    wx.openLocation({
      latitude: 23.362490,
      longitude: 116.715790,
      scale: 18,
      name: '华乾大厦',
      address: '金平区长平路93号'
    })
  },
  //拨打电话
  start_phone:function(){
    wx.makePhoneCall({
      phoneNumber: '1340000'
    })
  },
  // 选择地址
  chose_city: function (e) {
    var type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '../address/address?type=' + type,
    })
  },
  typebuy: function () {
    this.setData({
      buytype: !this.data.buytype
    })
  },
  // 车长选择性别
  chose_baby: function (e) {
    var index = e.currentTarget.dataset.index;
    var baby = this.data.choseB;
    this.setData({
      buyindex: index
    })
    // wx.request({
    //   url: '',
    //   data: {
    //   },
    //   success: function (res) {
    //     that.setData({
    //       list: res.data.data
    //     })
    //   }
    // })
  },
  chose_buyx: function (e) {
    var index = e.currentTarget.dataset.index;
    var buyx = this.data.choseC;
    this.setData({
      xingindex: index
    })
    // wx.request({
    //   url: '',
    //   data: {
    //   },
    //   success: function (res) {
    //     that.setData({
    //       list: res.data.data
    //     })
    //   }
    // })
  },
  click: function (e) {
    var id = e.currentTarget.dataset.id;
    console.log(id)
    if (id == 0) {
      this.setData({
        chose_c: true,
        martop:'170'
      })
    } else {
      this.setData({
        chose_c: false,
        martop: '80'
      })
    }
    this.setData({
      navindex: id
    })
    // wx.request({
    //   url: '',
    //   data: {
    //   },
    //   success: function (res) {
    //     that.setData({
    //       list: res.data.data
    //     })
    //   }
    // })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.id == 1) {
      this.setData({
        tabbarIndex: options.id
      })
      getApp().editTabBar1();
    } else {
      getApp().editTabBar();
    }
    let that = this
    if (!app.data.address.name) {
      wx.getLocation({
        type: 'gcj02',
        success: function (res) {
          console.log(res);
        },
      })
    }
    that.setData({
      city: app.data.address.name || "请选择",
      city1: app.data.address.name || "请选择",
    })
    wx.getSystemInfo({
      success(res){
        that.setData({
          scrollHeight: res.windowHeight
        });
      }

    }) 
  },
//下拉加载更多
  bindDownLoad(even){
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log('上拉刷新')
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('下拉')
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})